<%@ page import="net.zjitc.domain.User" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/18
  Time: 8:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--在四个域中添加值--%>
<%--1.pageContext代理其他域--%>
<%--2.直接使用域名对象设置--%>
<%
    pageContext.setAttribute("user","P");//在page域里设置值
    pageContext.setAttribute("user","R",pageContext.REQUEST_SCOPE);//在request域里设置值
    pageContext.setAttribute("user","S",pageContext.SESSION_SCOPE);//在session域里设置值
    pageContext.setAttribute("user","A",pageContext.APPLICATION_SCOPE);//在application域里设置值
%>
<%
    String str = (String) pageContext.getAttribute("user",pageContext.APPLICATION_SCOPE);//通过pageContext获得指定域的值
    String str2 = (String) request.getAttribute("user");//通过request对象获得request域中的user值
%>
<%=str%><br>
<%=str2%><br>

<%--pageContext全域查找--%>
<%
    String str3 = (String) pageContext.findAttribute("user");//从小到大查找域中的user
%>
<%=str3%><br>

<%--el表达式指定域查找--%>
<%
    User u = new User();
    u.setUsername("zhanagsan");
    u.setPassword("123");
    pageContext.setAttribute("user",u,pageContext.PAGE_SCOPE);

    Cookie cookie = new Cookie("user","lisi");
    response.addCookie(cookie);
%>
${pageScope.user.username}<br>
${pageScope.user.password}<br>

<%--el表达式全域查找--%>
${user}<br><%--从小到大查找域中的user--%>

${pageContext.request.contextPath}<br><%--获得当前项目名--%>
${pageContext.request.requestURL}<br>
${pageContext.request.requestURI}<br>
${pageContext.request.servletContext.serverInfo}<br><%--获得服务器名称--%>

${param.username}<br><%--获得参数--%>
${param.value[0]}<br><%--获得数组内参数--%>
${header["User-Agent"]}<br>
${cookie.user.name}<br><%--获得cookie名--%>
${cookie.user.value}<br><%--获得cookie值--%>

${initParam.chatset}<br>

</body>
</html>
